﻿@model XPressify.Models.PageModelDetails
@using XPressify.Data.Helpers
@using XPressify.Models
@using Omu.Awesome.Core;
@using Omu.Awesome.Mvc.Helpers;
@using XPressify.Controllers

@{
    ViewBag.Title = "Page details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


@if (Model.IsMember || Model.IsAdministrator || Model.PagePrivacyType == SubjectPrivacy.Public)
{
    
<fieldset>
        <legend style="font-size:x-large;color:#222">@Model.Name</legend>
        

        <table border="0">
        <tr>
            <td>
                @if (Model.HasCoverPictureAlbum)
                {
                    <a href='@Url.Action("AlbumDetails", "Album", new { id = Model.WallAlbumId })' class="nobtn">
                        <img src="@Model.WallAlbumCoverPicturePath" alt="Cover" title="Cover" style="width:150px;height:150px"/>
                    </a>
                }
                else
                {
                    <a href='@Url.Action("AlbumDetails", "Album", new { id = Model.WallAlbumId })' class="nobtn">
                        Album
                    </a>
                }
            </td>
            <td style="text-align:right;vertical-align:top">
                @if (Model.IsMember)
                {
                    @Html.Confirm("Are you sure you want to remove yourself from this page?", "myconfirmBtn", title: "Remove page", yesText: "Remove") 
                    using (Html.BeginForm("PageRemove", "Page", FormMethod.Post, new { style = "width:700px" }))
                    {
                                    @Html.HiddenFor(model => model.Id)
                                    <input type="submit" value="Leave" class="myconfirmBtn" id="nounderline" onmouseover="changeIdToObject(this)" onmouseout="changeIdToObject(this)"/>
                    }
                } 
                @if (Model.IsAdministrator)
                {
                    @Html.Confirm("Are you sure you want to delete this page?", "myconfirmBtn", title: "Delete page", yesText: "Delete") 
                        
                    using (Html.BeginForm("PageDelete", "Page", FormMethod.Post, new { style = "width:700px" }))
                    {
                                    @Html.HiddenFor(model => model.Id)
                                    <input type="submit" value="x" class="myconfirmBtn" id="nounderline" onmouseover="changeIdToObject(this)" onmouseout="changeIdToObject(this)"/>
                    }
                }
                @if (!Model.IsMember && !Model.IsAdministrator)
                {
                    @Html.ActionLink("Join", "BecomeMember", "Page", new { id = Model.Id }, new { @class = "abtn" })
                }
            </td>
        </tr>
        <tr>
            <td style="text-align: left;vertical-align:bottom">
                @if (Model.IsAdministrator)
                {  
                    @(Html.MakePopupForm<PageController>(o => o.PageEdit(Model.Id), title: "Edit", height: 520, width: 550, okText: "Save", resizable: false, refreshOnSuccess: true))
                    @(Html.PopupFormActionLink<PageController>(o => o.PageEdit(Model.Id), "Edit", new { @class = "nobtn" })) 
                }
            </td>
            <td></td>
        </tr>
        <tr>
            <td style="font-weight:bold;font-size:15px">
                Administrator:
                @if (Model.AdministratorBlocked == false)
                {
                    @Html.ActionLink(Model.Administrator.FullName, "ProfileView", "Profile", new { id = Model.Administrator.Id }, new { @class = "nobtn" })
                }
                else
                {
                    <div>Not available</div>
                } 
            </td>
        </tr>
        <tr>
            <td style="word-break:break-all;font-weight:bold;font-size:15px;width:30%">
                Description:
            </td>
            <td style="word-break:break-all;font-weight:bold;font-size:15px;color:#222">
                 @Model.Description
            </td>
        </tr>
        <tr>
            <td style="word-break:break-all;font-weight:bold;font-size:15px;width:30%">
                @if (Model.PagePrivacyType == SubjectPrivacy.Public)
                {
                    @:Public page
                }
                else
                {
                    @:Private page
                }
            </td>
            <td></td>
        </tr>
        <tr>
            <td>
                @(Html.MakePopupForm<PageController>(o => o.PageMembers(Model.Id), title: "Members", height: 600, width: 700, okText: "", resizable: false, refreshOnSuccess: true))
                @(Html.PopupFormActionLink<PageController>(o => o.PageMembers(Model.Id), "Members", new { @class = "abtn" }))
            </td>
            <td style="text-align:right">
                @if (Model.IsAdministrator || Model.IsMember)
                {
                    @(Html.MakePopupForm<PageController>(o => o.InviteFriendsToPage(Model.Id), title: "Invite friends", height: 350, width: 350, okText: "Invite", resizable: false, refreshOnSuccess: true))
                    @(Html.PopupFormActionLink<PageController>(o => o.InviteFriendsToPage(Model.Id), "Invite Friends", new { @class = "abtn" }))
                }
            </td>
        </tr>
    </table>

    </fieldset>

    
    if (Model.MembersCanPost || Model.IsAdministrator)
    {
        @Html.Partial("ShareLabel", new ShareLabelModel { LinkSubjectId = Model.Id, WallAlbumId = Model.WallAlbumId })

        <div id="contentHolderWrite">
            @Html.Partial("WriteStatus", new StatusCreateModel { Content = "Write something...", UserPostedOnId = Model.Id, BaseSubjectType = SubjectType.Page })    
        </div> 
    }
     

    <br />

    <div id="specialPeopleLikeList" style="display:none"></div>
    @Html.Confirm("Are you sure you want to delete this post?", "myconfirmBtn", title: "Delete post", yesText: "Delete")
    @Html.Confirm("Are you sure you want to delete this comment?", "myconfirmBtn1", title: "Delete comment", yesText: "Delete") 
    <div id="returnSuccessDelete"></div>
    
    <text>______________________________________________________________________________</text>

    <div id="@Model.Id"></div> 
    
        var specialUpdateId = "";
        foreach (var item in Model.AllPosts)
        {
        <div id="@item.Key.Id">
            <table border="0" cellpadding="0" cellspacing="0" style="margin:0px;padding:0px;width:553px">
                <tr>
                    <th style="padding: 0px 2px 0px 2px;"> 
                        @Html.Raw(item.Key.Content)
                    </th>
                    @if (Model.IsAdministrator || item.Key.BaseSubject.Id == Model.CurrentUser.Id || (item.Key.Creator != null && item.Key.Creator.Id == Model.CurrentUser.Id))
                    {
                        <td style="padding: 0px 2px 0px 2px;vertical-align:top;background-color: #E8EEF4;text-align:right">
                            @Html.Partial("BtnPostDelete", new BtnPostDeleteModel { PostId = item.Key.Id })
                        </td>
                    }
                </tr>
            </table>
   
            @foreach (var comment in item.Value)
            {   
                <div id="@comment.Id">
                    <table border="0" cellpadding="0" cellspacing="0" style="margin:0px;padding:0px;width:553px">
                        <tr>
                            <th width="0px" style="padding: 0px 2px 0px 2px"> 
                                @Html.Raw(comment.Content)
                            </th>
                            @if (comment.BaseSubject.Id == Model.CurrentUser.Id || Model.IsAdministrator)
                            {
                                <th style="padding: 0px 2px 0px 2px;vertical-align: top;text-align:right"> 
                                    @Html.Partial("BtnPostCommentDelete", new BtnPostDeleteModel { PostId = comment.Id })
                                </th>
                            }
                        </tr>
                    </table>
                </div>
            }

            @{specialUpdateId = item.Key.Id + "Update";}
            <div id="@specialUpdateId"></div>
        
            @if (item.Key.CommentType != CommentType.PostWithoutComments)
            {
                @Html.Partial("WriteComment", new PostCommentModel { PostId = item.Key.Id, ContentText = "Write a comment...", ProfilePicturePath = Model.CurrentUserProfilePicturePath })
            }
    
            ______________________________________________________________________________
        </div>
    }




}